package com.atguigu.yygh.cmn.service;

import com.atguigu.yygh.model.cmn.Dict;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class RedisService {
    @Cacheable(value = "dict", key = "#id")
    public List<Dict> selectById(Long id) {
        List<Dict> dicts = new ArrayList<>();
        for (int i = 10; i < 20; i++) {
            Dict dict = new Dict();
            dict.setHasChildren(true);
            dict.setDictCode("123");
            dict.setId(id+i);
            dicts.add(dict);
        }
        return dicts;
    }

    @CachePut(value="dict",key = "#id")
    public Dict  update(Long id ){
        // 2. 更新数据库 , 再更新redis
        Dict dict = new Dict();
        dict.setHasChildren(true);
        dict.setDictCode("123");
        dict.setId(10L);
        return dict;
    }

}
